package hotel.modal;

import hotel.dao.EmployeeDao;
import javafx.beans.property.*;

public class Employee {
	private SimpleIntegerProperty employeeId;	// 员工编号
	private SimpleStringProperty name;			// 员工姓名
	private SimpleStringProperty gender;		// 员工性别
	private SimpleStringProperty birthday;		// 出生日期
	private SimpleStringProperty phone;			// 联系电话
	private SimpleStringProperty entryTime;		// 入职时间
	private SimpleStringProperty certId;		// 身份证号
	//private SimpleDoubleProperty salary;		// 基本工资
	private SimpleBooleanProperty status;		// 员工状态
	private SimpleStringProperty address;		// 家庭住址
	private SimpleBooleanProperty modified;
	
	private void init(EmployeeDao ed) {
		if(ed != null) {
			this.employeeId = new SimpleIntegerProperty(ed.getEmployeeId());
			this.name = new SimpleStringProperty(ed.getName());
			this.gender = new SimpleStringProperty(ed.getGender());
			this.birthday = new SimpleStringProperty(ed.getBirthday());
			this.phone = new SimpleStringProperty(ed.getPhone());
			this.entryTime = new SimpleStringProperty(ed.getEntryTime());
			this.certId = new SimpleStringProperty(ed.getCertId());
			//this.salary = new SimpleDoubleProperty("");
			this.status = new SimpleBooleanProperty(ed.getStatus());
			this.address = new SimpleStringProperty(ed.getAddress());
		}else {
			this.employeeId = new SimpleIntegerProperty(-1);
			this.name = new SimpleStringProperty("");
			this.gender = new SimpleStringProperty("");
			this.birthday = new SimpleStringProperty("");
			this.phone = new SimpleStringProperty("");
			this.entryTime = new SimpleStringProperty("");
			this.certId = new SimpleStringProperty("");
			//this.salary = new SimpleDoubleProperty("");
			this.status = new SimpleBooleanProperty(false);
			this.address = new SimpleStringProperty("");
		}
		this.modified = new SimpleBooleanProperty(false);
	}
	
	public Employee(EmployeeDao ed) {
		init(ed);
	}
	
	public Employee() {
		init(null);
	}
	
	public Object getDao() {
		EmployeeDao ed = new EmployeeDao();
		ed.setEmployeeId(employeeId.get());
		ed.setName(name.get());
		ed.setGender(gender.get());
		ed.setBirthday(birthday.get());
		ed.setPhone(phone.get());
		ed.setEntryTime(entryTime.get());
		ed.setCertId(certId.get());
		ed.setStatus(status.get());
		ed.setAddress(address.get());
		return ed;
	}
	
	public Employee(Employee employee) {
		this.employeeId = new SimpleIntegerProperty(employee.getEmployeeId());
		this.name = new SimpleStringProperty(employee.getName());
		this.gender = new SimpleStringProperty(employee.getGender());
		this.birthday = new SimpleStringProperty(employee.getBirthday());
		this.phone = new SimpleStringProperty(employee.getPhone());
		this.entryTime = new SimpleStringProperty(employee.getEntryTime());
		this.certId = new SimpleStringProperty(employee.getCertId());
		//this.salary = new SimpleDoubleProperty(employee.getSalary());
		this.status = new SimpleBooleanProperty(employee.isStatus());
		this.address = new SimpleStringProperty(employee.getAddress());
		this.modified = new SimpleBooleanProperty(false);
	}
	
	public Employee(int employeeId, String name, String gender, String birthday, 
			String phone, String entryTime, String certId, int status, String address) {
		this.employeeId = new SimpleIntegerProperty(employeeId);
		this.name = new SimpleStringProperty(name);
		this.gender = new SimpleStringProperty(gender);
		this.birthday = new SimpleStringProperty(birthday);
		this.phone = new SimpleStringProperty(phone);
		this.entryTime = new SimpleStringProperty(entryTime);
		this.certId = new SimpleStringProperty(certId);
		//this.salary = new SimpleDoubleProperty(salary);
		if(status > 0) this.status = new SimpleBooleanProperty(true);
		else this.status = new SimpleBooleanProperty(false);
		this.address = new SimpleStringProperty(address);
		this.modified = new SimpleBooleanProperty(false);
	}
	
	public String toString() {
		String str = String.format(" EmployeeID: %s  Name: %s Gender:%s  Birthday: %s  Phone:%s"+
									" EntryTime: %s  CertID: %s  Status: %s  Address: %s", 
									employeeId.get(), name.get(), gender.get(), birthday.get(), 
									phone.get(), entryTime.get(), certId.get(), status.get()?"在职":"离职", address.get());
		return str;
	}

	public final SimpleIntegerProperty employeeIdProperty() {
		return this.employeeId;
	}

	public final int getEmployeeId() {
		return this.employeeIdProperty().get();
	}

	public final void setEmployeeId(final int employeeId) {
		this.employeeIdProperty().set(employeeId);
	}

	public final SimpleStringProperty nameProperty() {
		return this.name;
	}

	public final String getName() {
		return this.nameProperty().get();
	}

	public final void setName(final String name) {
		this.nameProperty().set(name);
	}

	public final SimpleStringProperty genderProperty() {
		return this.gender;
	}

	public final String getGender() {
		return this.genderProperty().get();
	}

	public final void setGender(final String gender) {
		this.genderProperty().set(gender);
	}

	public final SimpleStringProperty birthdayProperty() {
		return this.birthday;
	}

	public final String getBirthday() {
		return this.birthdayProperty().get();
	}

	public final void setBirthday(final String birthday) {
		this.birthdayProperty().set(birthday);
	}

	public final SimpleStringProperty phoneProperty() {
		return this.phone;
	}

	public final String getPhone() {
		return this.phoneProperty().get();
	}

	public final void setPhone(final String phone) {
		this.phoneProperty().set(phone);
	}

	public final SimpleStringProperty entryTimeProperty() {
		return this.entryTime;
	}

	public final String getEntryTime() {
		return this.entryTimeProperty().get();
	}

	public final void setEntryTime(final String entryTime) {
		this.entryTimeProperty().set(entryTime);
	}

	public final SimpleStringProperty certIdProperty() {
		return this.certId;
	}

	public final String getCertId() {
		return this.certIdProperty().get();
	}

	public final void setCertId(final String certId) {
		this.certIdProperty().set(certId);
	}

	public final SimpleBooleanProperty statusProperty() {
		return this.status;
	}

	public final boolean isStatus() {
		return this.statusProperty().get();
	}

	public final void setStatus(final boolean status) {
		this.statusProperty().set(status);
	}

	public final SimpleStringProperty addressProperty() {
		return this.address;
	}

	public final String getAddress() {
		return this.addressProperty().get();
	}

	public final void setAddress(final String address) {
		this.addressProperty().set(address);
	}

	public final SimpleBooleanProperty modifiedProperty() {
		return this.modified;
	}

	public final boolean isModified() {
		return this.modifiedProperty().get();
	}

	public final void setModified(final boolean modified) {
		this.modifiedProperty().set(modified);
	}
}
